package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.record.SpaceVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by lzh on 2018/3/17.
 */

public class SpaceInfoAdapter extends LemonRcvAdapter<SpaceVo> {
    private RecyclerTClickListener<SpaceVo> mListener;

    public SpaceInfoAdapter(@Nullable List<SpaceVo> data, RecyclerTClickListener<SpaceVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new SpaceItem();
    }

    public class SpaceItem implements AdapterItem<SpaceVo> {

        @Bind(R.id.tv_space_name)
        TextView tvSpaceName;
        @Bind(R.id.tv_space_count)
        TextView tvSpaceCount;
        @Bind(R.id.tv_main_danger_thing)
        TextView tvMainDangerThing;
        @Bind(R.id.tv_cause_danger_type)
        TextView tvCauseDangerType;
        @Bind(R.id.tv_space_address)
        TextView tvSpaceAddress;
        @Bind(R.id.tv_safe_equipment)
        TextView tvSafeEquipment;
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;
        private SpaceVo data;
        private int pos;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_space_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data,pos);
                }
            });
        }

        @Override
        public void handleData(SpaceVo spaceVo, int position) {
            data = spaceVo;
            pos = position;
            tvSpaceName.setText(CommonUtil.avoidNullString(spaceVo.getName()));
            tvSpaceCount.setText(CommonUtil.avoidNullString(spaceVo.getNumber()));
            tvMainDangerThing.setText(CommonUtil.avoidNullString(spaceVo.getMainHazardous()));
            tvCauseDangerType.setText(CommonUtil.avoidNullString(spaceVo.getAccidentProne()));
            tvSpaceAddress.setText(CommonUtil.avoidNullString(spaceVo.getPosition()));
            tvSafeEquipment.setText(CommonUtil.avoidNullString(spaceVo.getSafetyMeasures()));
        }
    }
}
